﻿using project.B12.Model.Common;

namespace project.B12.Model.BaseModel
{
    /// <summary>
    /// 通用返回类
    /// </summary>
    public class MessageModel<T>
    {
        public MessageModel()
        {
        }

        /// <summary>
        /// 是否操作成功
        /// </summary>
        public bool Success { get; set; }

        public uint Code { get; set; } = 0;

        /// <summary>
        /// 返回信息
        /// </summary>
        public string Message { get; set; } = "";

        public string? Header { get; set; } = "";

        /// <summary>
        /// 返回数据
        /// </summary>
        public T? Result { get; set; }

        public override string ToString()
        {
            return Message;
        }

        /// <summary>
        /// 返回成功
        /// </summary>
        /// <param name="msg">消息</param>
        /// <param name="response">数据</param>
        /// <returns></returns>
        public static MessageModel<T> ReturnSuccess(string msg, T response)
        {
            return ReturnMessage(true, msg, response);
        }
        /// <summary>
        /// 返回成功
        /// </summary>
        /// <param name="msg">消息</param>
        /// <param name="response">数据</param>
        /// <returns></returns>
        public static MessageModel<T> ReturnSuccess(Enum msg, T response)
        {
            return ReturnMessage(true, EnumUtil.GetEnumDisplay(msg), response);
        }

        /// <summary>
        /// 返回成功
        /// </summary>
        /// <param name="msg">消息</param>
        /// <param name="response">数据</param>
        /// /// <param name="header">标题</param>
        /// <returns></returns>
        public static MessageModel<T> ReturnSuccess(string msg, T response, string header)
        {
            return ReturnMessage(true, msg, response, header);
        }

        /// <summary>
        /// 返回成功
        /// </summary>
        /// <param name="msg">数据</param>
        /// <param name="response"></param>
        /// <param name="header">标题</param>
        /// <returns></returns>
        public static MessageModel<T> ReturnSuccess(Enum msg, T response, string header)
        {
            return ReturnMessage(true, msg, response, header);
        }

        /// <summary>
        /// 返回失败
        /// </summary>
        /// <param name="msg">消息</param>
        /// <param name="response">数据</param>
        /// <returns></returns>
        public static MessageModel<T> ReturnFail(string msg, T? response = default)
        {
            return ReturnMessage(false, msg, response);
        }
        /// <summary>
        /// 返回失败
        /// </summary>
        /// <param name="msg">消息</param>
        /// <param name="response">数据</param>
        /// <returns></returns>
        public static MessageModel<T> ReturnFail(Enum msg, T? response = default)
        {
            return ReturnMessage(false, EnumUtil.GetEnumDisplay(msg), response);
        }

        /// <summary>
        /// 返回失败
        /// </summary>
        /// <param name="msg">消息</param>
        /// <param name="response">数据</param>
        /// <param name="header">标题</param>
        /// <returns></returns>
        public static MessageModel<T> ReturnFail(string msg, T response, string header)
        {
            return ReturnMessage(false, msg, response, header);
        }

        /// <summary>
        /// 返回消息
        /// </summary>
        /// <param name="success">失败/成功</param>
        /// <param name="msg">消息</param>
        /// <param name="response">数据</param>
        /// <param name="header">标题</param>
        /// <returns></returns>
        public static MessageModel<T> ReturnMessage(bool success, string msg, T response, string header)
        {
            return new MessageModel<T>() { Message = msg, Result = response, Success = success, Header = header };
        }

        /// <summary>
        /// 返回消息
        /// </summary>
        /// <param name="success">失败/成功</param>
        /// <param name="msg">消息</param>
        /// <param name="response">数据</param>
        /// <returns></returns>
        public static MessageModel<T> ReturnMessage(bool success, string msg, T? response)
        {
            return new MessageModel<T>() { Message = msg, Result = response, Success = success };
        }

        ///  <summary>
        ///  返回消息
        ///  </summary>
        ///  <param name="success">失败/成功</param>
        ///  <param name="msg"></param>
        ///  <param name="response">数据</param>
        ///  <param name="header">标题</param>
        ///  ///
        ///  <returns></returns>
        public static MessageModel<T> ReturnMessage(bool success, Enum msg, T response, string header)
        {
            return ReturnMessage(success, EnumUtil.GetEnumDisplay(msg) , response,  header);
        }
    }

    /// <summary>
    /// 无结果返回
    /// </summary>
    public class MessageModel
    {
        public uint Code { get; set; } = 0;

        /// <summary>
        /// 操作是否成功
        /// </summary>
        public bool Success { get; set; }

        /// <summary>
        /// 返回信息
        /// </summary>
        public string Message { get; set; } = "";

        /// <summary>
        /// 返回信息
        /// </summary>
        public string? Header { get; set; } = "";

        /// <summary>
        /// 返回失败
        /// </summary>
        /// <param name="msg">消息</param>
        /// <returns></returns>
        public static MessageModel ReturnFail(string msg)
        {
            return ReturnMessage(false, msg);
        }

        /// <summary>
        /// 返回成功
        /// </summary>
        /// <param name="response">数据</param>
        /// <param name="header">标题</param>
        /// <returns></returns>
        public static MessageModel ReturnFail(Enum response, string? header)
        {
            return ReturnMessage(false, response, header);
        }

        /// <summary>
        /// 返回成功
        /// </summary>
        /// <param name="response">数据</param>
        /// <param name="header">标题</param>
        /// <returns></returns>
        public static MessageModel ReturnSuccess(Enum response, string? header)
        {
            return ReturnMessage(true, response, header);
        }

        /// <summary>
        /// 返回失败
        /// </summary>
        /// <param name="msg">消息</param>
        /// <param name="header">标题</param>
        /// <returns></returns>
        public static MessageModel ReturnFail(string msg, string? header)
        {
            return ReturnMessage(false, msg, header);
        }

        /// <summary>
        /// 返回成功
        /// </summary>
        /// <param name="msg">消息</param>
        /// <returns></returns>
        public static MessageModel ReturnSuccess(string msg)
        {
            return ReturnMessage(true, msg);
        }

        /// <summary>
        /// 返回成功
        /// </summary>
        /// <returns></returns>
        public static MessageModel ReturnSuccess()
        {
            return ReturnMessage(true, string.Empty);
        }

        /// <summary>
        /// 返回成功
        /// </summary>
        /// <param name="msg">消息</param>
        /// <param name="header">标题</param>
        /// <returns></returns>
        public static MessageModel ReturnSuccess(string msg, string? header)
        {
            return ReturnMessage(true, msg, header);
        }

        /// <summary>
        /// 返回消息
        /// </summary>
        /// <param name="success">失败/成功</param>
        /// <param name="msg">消息</param>
        /// <returns></returns>
        public static MessageModel ReturnMessage(bool success, string msg)
        {
            return new MessageModel() { Message = msg, Success = success };
        }

        /// <summary>
        /// 返回消息
        /// </summary>
        /// <param name="success">失败/成功</param>
        /// <param name="msg">消息</param>
        /// <param name="header">标题</param>
        /// <returns></returns>
        public static MessageModel ReturnMessage(bool success, string msg, string? header)
        {
            return new MessageModel() { Message = msg, Success = success, Header = header };
        }

        /// <summary>
        /// 返回消息
        /// </summary>
        ///<param name="success">失败/成功</param>
        /// <param name="response">数据</param>
        /// /// <param name="header">标题</param>
        /// <returns></returns>
        public static MessageModel ReturnMessage(bool success, Enum response, string? header)
        {
            return ReturnMessage(success, EnumUtil.GetEnumDisplay(response), header);
        }
    }
}
